package com.dk.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dk.data.PageBean;
import com.dk.mapper.CarMapper;
import com.dk.pojo.Car;
import com.dk.service.CarService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
@org.springframework.stereotype.Service
public class CarServiceImpl implements CarService {

    @Autowired
    private CarMapper carMapper;

    @Override
    public PageBean<Car> findAll(String cname,Integer ctype,Integer pageNumber, Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        List<Car> list = carMapper.getInfo(cname,ctype);
        PageInfo<Car> page = new PageInfo<>(list);
        return new PageBean<>(page.getPageNum(),page.getPageSize(),page.getTotal(),page.getList());
    }

    @Override
    public Boolean saveInfo(Car car) {
        Integer i = carMapper.insertSelective(car);
        return i > 0;
    }

    @Override
    public Car getById(Integer cid) {
        return carMapper.selectByPrimaryKey(cid);
    }

    @Override
    public Boolean updateInfo(Car car) {
        Integer i = carMapper.updateByPrimaryKeySelective(car);
        return i > 0;
    }

    @Override
    public Boolean deleteInfo(Integer cid) {
        Integer i = carMapper.deleteByPrimaryKey(cid);
        return i > 0;
    }

    @Override
    public Integer deleteById(Integer[] cid) {
        return carMapper.deleteById(cid);
    }

}
